package com.wyvoid.forum.web.action.admin.usergroup;

import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;
import com.wyvoid.forum.web.action.admin.BaseAdminAction;
import com.wyvoid.forum.service.IUserGroupService;
import com.wyvoid.forum.service.IUserService;
import com.wyvoid.forum.domain.UserGroup;
import com.wyvoid.forum.domain.User;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: wangchao
 * Date: 2007-7-22
 * Time: 15:00:12
 * To change this template use File | Settings | File Templates.
 */
@UrlBinding(value = "/admin/SetUserGroup.do")
public class SetUserGroupAction extends BaseAdminAction {
    @SpringBean
    private IUserGroupService userGroupService;
    @SpringBean
    private IUserService userService;
    private long userId;
    private List userGroupList;
    private User user;

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public List getUserGroupList() {
        return userGroupList;
    }

    public void setUserGroupList(List userGroupList) {
        this.userGroupList = userGroupList;
    }

    public void setUserGroupService(IUserGroupService userGroupService) {
        this.userGroupService = userGroupService;
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }



    

    @DefaultHandler
    public Resolution setUserGroupForm() {
        userGroupList = userGroupService.getMemberUserGroups();
        user=userService.getUser(userId);
        return getAdminResolution("usergroup/setUserGroup");
    }

    public Resolution setUserGroup(){
        User updateUser=userService.getUser(user.getId());
        updateUser.setGroupId(user.getGroupId());
        userService.updateUser(updateUser);
        return new RedirectResolution("/forum/admin/editUsers.do", false);
    }
}
